#include <Core/Box/BoxInstance.h>
#include <Core/DefaultCommandScheduler.h>

#include <iostream>
#include <boost/lexical_cast.hpp>

#define MY_DEBUG true

/**
 * My Box interfaces implementation
 */
class MyBoxEventSubscriber : public BoxCore::IBoxEventSubscriber {
public :
	MyBoxEventSubscriber() { }
	virtual ~MyBoxEventSubscriber() { }
	
	virtual void registred() 
		{ MY_DEBUG && (std::cerr << __FUNCTION__ << std::endl); }

	virtual void unregistred() 
		{ MY_DEBUG && (std::cerr << __FUNCTION__ << std::endl); }

	virtual void onWorkerStart(int slotId) 
		{ MY_DEBUG && (std::cerr << __FUNCTION__ << ", args : id " << slotId << std::endl); }

	virtual void onWorkerComplete(int slotId) 
		{ MY_DEBUG && (std::cerr << __FUNCTION__ << ", args : id " << slotId << std::endl); }

	virtual void onWorkerCompleteWithError(int slotId, BoxCore::BoxErrorStruct const & boxError)
		{ MY_DEBUG && (std::cerr << __FUNCTION__ << ", args : id  " << slotId << ", boxerr " << toString(boxError) << std::endl); }

private :
	inline std::string toString(BoxCore::BoxErrorStruct const & errorStruct) const 
	{ 	
		std::stringstream stringStream;
		return stringStream.str();
	}

};

/**
 * Entry point 
 */
int main(int argc, char ** argv) 
try 
{
	
	Core::DefaultCommandSchedulerParams const commandSchedulerParams = { 10 };
	Core::initializeDefaultCommandScheduler(commandSchedulerParams);

	BoxCore::BoxAsioTransportParams const transportParams = { "localhost", 5999, 10 };
	BoxCore::ITransportLayerPtr transport(new BoxCore::BoxAsioTransport(transportParams));

	BoxCore::BoxInstanceParams const boxInstanceParams = { std::string("sig-scaner-server-slave1"), true };
	BoxCore::BoxInstance server(boxInstanceParams);

	server.initialize(transport, Core::defaultScheduler());	
	
	server.startInstance();
	server.waitInstance();
	std::cin.get();
	
	return 0;
} 
catch (std::exception const & expt) 
{
	std::cerr << "Exception : " << expt.what() << std::endl;
	return EXIT_FAILURE;
}

